home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / natcomp.zip / NAT.CB < prev   
Text File  |  1990-02-23  |  3KB  |  132 lines

  1. /* _init macro.
  2.  *     Do not change this macro (always overwritten by Setup
  3.  */
  4.  
  5. _init()
  6. {
  7.     extern    autosave,                    /* External macro declarations */
  8.                 toggle_re;
  9.  
  10.     color( 7, 0, 1, 1, 4, 0x80 );        /* Set the screen colors */
  11.     autosave();                                /* Automatic file save when idle */
  12. }
  13.  
  14. /* Initials macro.
  15.  *    Use this macro for additional customization.
  16.  */
  17.  
  18. #include <nat.h>
  19.  
  20. NAT()
  21. {
  22.     load_macro( "file_ed5" );
  23.  
  24.     autoload( "ascii", "ascii" );
  25.     assign_to_key( "<Ctrl-a>", "ascii" );
  26.  
  27.     autoload( "diff", "diff" );
  28.     assign_to_key( "<Ctrl-d>", "diff" );
  29.     
  30.     autoload( "calc", "calc" );
  31.     assign_to_key( "<Alt-F1>", "calc" );
  32.     
  33.     load_macro( "rat" );
  34.     /* key assignments are made in rat.cb _init macro:
  35.      *            crtl-L = left  mouse button
  36.      *            crtl-R = right mouse button            These must agree w/ mouse.def
  37.      *            ctrl-B = both  mouse buttons            mouse menu driver
  38.      */
  39.  
  40.     autoload( "whichkey", "whichkey" );
  41.     assign_to_key( "<Ctrl-k>", "whichkey" );
  42.  
  43.     autoload( "freekey", "freekey" );
  44.  
  45.     autoload( "dir", "dir" );
  46.     assign_to_key( "<Ctrl-F1>", "dir" );
  47.  
  48.     autoload( "ctags", "ctag" );
  49.     assign_to_key( "<Ctrl-F10>", "ctag" );
  50.     
  51.     autoload( "switcase", "switcase" );
  52.     
  53.     autoload( "grep", "grep" );
  54.     autoload( "grep_r", "grep_r" );
  55.     
  56.     autoload( "outline", "outline" );
  57.     autoload( "linedraw", "linedraw" );
  58.                                 
  59.     return;
  60.         
  61. }        
  62.  
  63. /* File Extension Macros, etc.
  64.  * macros marked "overwritable" may be overwritten by setup.
  65.  */
  66.  
  67. /* Overwritable by Setup */
  68. default (...)
  69. {
  70.     tabs (4, 7);
  71. }
  72.  
  73.  
  74. /*   read_word:
  75.  *
  76.  *    Reads one alphanumeric word starting at current position.
  77.  *    Returns the ascii string read from the word itself.
  78.  *    Srch_code is a code that determines what type of "word" to search for.
  79.  *     0 = non whitespace word
  80.  *     1 = alphanumeric word
  81.  *        2 = variable string (C-syntax)
  82.  */
  83.  
  84. string read_word( int srch_code )        /* reads next word, position moves past the end of word */
  85. {
  86.     string srch_str, nxtc, word = "";
  87.  
  88.     switch( srch_code )
  89.     {
  90.         case 0:
  91.             srch_str = WHTSPC;
  92.         case 1:
  93.             srch_str = _ALPHNUM;
  94.         case 2:
  95.             srch_str = _VARNAM;
  96.         default:
  97.             error("Error: read_word: %d not a valid search code");
  98.     }
  99.  
  100.     search_back (srch_str);            /* get to the start of the word I'm in */
  101.     search_fwd  (srch_str);
  102.     
  103.     next_char();
  104.     nxtc = read(1);
  105.     while( !search_string( srch_str, nxtc ) )
  106.     {
  107.         word += nxtc;
  108.         next_char();
  109.         nxtc = read(1);
  110.     }
  111.     return( word );
  112. }
  113.  
  114. string trans_envar( string cmdln )            /* NAT -- added 1/14/90 */
  115. {                                                        /* transl %VAR% to ascii string */
  116.     int        pos, len;
  117.     string    cmdln0 = cmdln,                    /* made into a recursive call */
  118.                 new_cmdln = "",                    /* so env vars may have env vars */
  119.                 envstr;
  120.  
  121.     while( pos = search_string( "[%][A-Za-z0-9_]+[%]", cmdln0, len ) )
  122.     {
  123.         new_cmdln += substr( cmdln0, 1, pos-1 );
  124.         envstr = substr( cmdln0, pos+1, len-2 );        /* don't include %'s */
  125.         new_cmdln += inq_environment( envstr );        /* trans and append */
  126.         cmdln0 = substr( cmdln0, pos+len+1 );            /* move past env var */
  127.     }
  128.     if( search_string( "[%][A-Za-z0-9_]+[%]", new_cmdln, len ) )
  129.         new_cmdln = trans_envar( new_cmdln );
  130.     return trim( ltrim( new_cmdln + " " + cmdln0 ) );
  131. }
  132.